layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    laydate.render({
        elem: '#createtime', //指定元素
        type: 'datetime',
        trigger: 'click',
        format:'yyyy/MM/dd HH:mm:ss'
    });

    $.ajax({
        url:"/classes/selectall?page=1&limit=100",
        type: 'get',
        success: function (data) {
            data=data.data;
            //使用循环遍历，给下拉列表赋值
            $.each(data, function (index, value) {
                $('#classid').append(new Option(value.cname,value.id));// 下拉菜单里添加元素
            });
            layui.form.render("select");//重新渲染 固定写法
        }
    })




    form.on("submit(addStudent)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

        if(data.field.id!=""){
            $.ajax({
                url:"/student/update",
                type:"post",
                data:data.field,
                success:function(res){
                    /*关掉等待框*/
                    top.layer.close(index);
                    /*提示信息*/
                    top.layer.msg(res.msg);

                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }
            })
        }else {
            $.ajax({
                url:"/student/add",
                type:"post",
                data:data.field,
                success:function(res){
                    /*关掉等待框*/
                    top.layer.close(index);
                    /*提示信息*/
                    top.layer.msg(res.msg);

                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }
            })
        }


        /*防止主线程提交*/
        return false;
    })





})